package com.ler.yrmall.coupon.controller;

import com.ler.yrmall.coupon.entity.SeckillEntity;
import com.ler.yrmall.coupon.service.SeckillService;
import com.ler.yrmall.basic.Form;
import com.ler.yrmall.basic.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;


/**
 * @author Leron
 */
@RestController
@RequestMapping("/seckill")
public class SeckillController {

    @Resource
    private SeckillService seckillSessionService;

    /**
     * 列表
     */
    @RequestMapping("/find")
    public Result<?> list(Form request) {
        return Result.ok(seckillSessionService.find(request));
    }


    /**
     * 信息
     */
    @RequestMapping("/getById/{id}")
    public Result<?> info(@PathVariable("id") Long id) {
        SeckillEntity seckillSession = seckillSessionService.getById(id);
        return Result.ok(seckillSession);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public Result<?> save(@RequestBody SeckillEntity seckillSession) {
        seckillSessionService.save(seckillSession);
        return Result.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public Result<?> update(@RequestBody SeckillEntity seckillSession) {
        seckillSessionService.updateById(seckillSession);
        return Result.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public Result<?> delete(@RequestBody Long[] ids) {
        seckillSessionService.removeByIds(Arrays.asList(ids));
        return Result.ok();
    }

    // 移动端

    @GetMapping("/getSeckill")
    public Result<?> getSessionInfo() {
        return Result.ok(seckillSessionService.getSeckillInfo());
    }

}
